package com.hiray.wanandroid.data

import androidx.compose.runtime.mutableStateListOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import com.hiray.wanandroid.net.ApiHelper
import com.hiray.wanandroid.net.apiCall
import com.hiray.wanandroid.net.response.HomeBanner
import kotlinx.coroutines.launch

class WanViewModel : ViewModel() {
    private val homeFeedSource = HomeFeedSource()
    val feedFlow = Pager(PagingConfig(20)) { homeFeedSource }.flow
    val banners = mutableStateListOf<HomeBanner>()

    fun fetchBanner() {
        viewModelScope.launch {
            val res = apiCall { ApiHelper.api().fetchHomeBanner() }
            banners.clear()
            banners.addAll(res.data ?: emptyList())
        }
    }
}